<?php
/**
 * create by breeze
 * Author: breeze
 * Date: 2021/3/29
 */

namespace app\index\controller;
use app\index\business\consignorBus;
use app\index\validate\consignorItem;
use think\Exception;
use think\exception\ValidateException;
use think\facade\View;
class Consignor extends IndexBase
{
    public function index(){
        View::assign('title','货主企业');
        return View::fetch();
    }
    public function edit(){
        View::assign('title','修改');
        return View::fetch();
    }
    public function noticeList(){
        View::assign('title','我的发布');
        return View::fetch();
    }
    public function noticeEdit(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        View::assign('title','修改');
        return View::fetch();
    }
    public function noticeDetail(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        View::assign('title','详情');
//
        return View::fetch();
    }
    public function facilitator(){
        View::assign('title','运力服务商');
        return View::fetch();
    }
    public function reset(){
        View::assign('title','重置密码');
        return View::fetch();
    }
    public function detail(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        View::assign('title','运力服务商详情');
        return View::fetch();
    }
    public function addItemDetail(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        View::assign('title','详情');
        return View::fetch();
    }
    public function addNoticeItem(){

        $postDate = $this->request->param("postDate");
        $postDate['status'] = 1;
        try {
            validate(consignorItem::class)->scene('addNoticeItem')->check($postDate);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getError());
        }
        $consignorBus = new consignorBus();
        $res = $consignorBus->addNoticeItemBus($postDate);
        return show(config('status.success'),'添加成功',$res);
    }
    public function updateNoticeItem(){

        $postDate = $this->request->param("postDate");
        $id = $this->request->param("id");
        $postDate['status'] = 1;
        $where = ["id"=>$id];
//        dump($postDate);exit();
        try {
            validate(consignorItem::class)->scene('addNoticeItem')->check($postDate);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getError());
        }
        $consignorBus = new consignorBus();

        $res = $consignorBus->updateNoticeItemBus($where,$postDate);
        return show(config('status.success'),'修改成功，请等待审核',$res);
    }
    public function getNoticeItem(){
//        $postDate = $this->request->param("postDate");
        $where = $this->request->param("where");
        $paging = $this->request->param("paging");
        $consignorBus = new consignorBus();
        $res = $consignorBus->getNoticeItemBus($where,$paging);
        return show(config('status.success'),'查询成功',$res);
    }
    public function getNoticeItemById(){
        $id = $this->request->param("id");
        $consignorBus = new consignorBus();
        try {
            $res = $consignorBus->getItemByIdBus($id);
        } catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'获取成功',$res);
    }

    /**
     * 详情页获取发布项目信息
     * @return \think\response\Json
     */
    public function getNoticeDetail(){
        $id = $this->request->param('id');
        $member_id = $this->request->param('member_id');
        $where = [
            'id'=>$id,
            'member_id'=>$member_id
        ];
        $consignorBus = new consignorBus();
        try {
            $res = $consignorBus->getNoticeDetailBus($where);
        } catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'获取成功',$res);
    }


    /**获取facilitator分页数据
     * @return \think\response\Json
     * @throws Exception
     */
    public function getFacilitatorList(){
        $where = $this->request->param("where");
        if (empty($where)){
            $where = [];
        }
        $paging = $this->request->param("paging");
        $member_id = $this->request->param('member_id');
//        dump($where);exit();
        $consignorBus = new consignorBus();
        $res = $consignorBus->getFacilitatorListBus($where,$paging,$member_id);
        return show(config('status.success'),'查询成功',$res);
    }

    /**根据传的条件更改运力服务商的状态
     * @return \think\response\Json
     */
    public function changeFacilitatorField(){
        $where = $this->request->param("where");
        $data = $this->request->param("data");
        $consignorBus = new consignorBus();
        try {
            $res = $consignorBus->changeFacilitatorFieldBus($where,$data);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'更改成功',$res);
    }
    public function getFacilitatorDetail(){
        $member_info_member_id = $this->request->param("member_info_member_id");
        $member_id = $this->request->param("member_id");
        $consignorBus = new consignorBus();
        try {
            $res = $consignorBus->getFacilitatorDetailBus($member_info_member_id,$member_id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'查询成功',$res);
    }
    public function getConsignorItemAddMemberListPage(){
        $where = $this->request->param('where');
        $paging = $this->request->param('paging');
        $consignorBus = new consignorBus();
        try {
            $res = $consignorBus->getConsignorItemAddMemberListPageBus($where,$paging);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'查询成功',$res);
    }
    public function getConsignorItemAddMemberDetail(){
        $member_id = $this->request->param('member_id');
        $where = [
            'member_id' => $member_id
        ];
        $consignorBus = new consignorBus();
        try {
            $res = $consignorBus->getConsignorItemAddMemberDetailBus($member_id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'查询成功',$res);
    }
    public function changeConsignorItemAddMemberStatus(){
        $id = $this->request->param('id');
        $consignorBus = new consignorBus();
        try {
            $res = $consignorBus->changeConsignorItemAddMemberStatusBus($id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'更改成功',$res);
    }
    public function RemoveConsignorItem(){
        $id = $this->request->param('id');
        $consignorBus = new consignorBus();
        try {
            $res = $consignorBus->RemoveConsignorItemBus($id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'删除成功',$res);
    }
}
